co = coroutine.create(function () print("hi") end)
print(co)  --> thread: 0x7fa8a8d05160

-- coroutine can be in one of four states:
-- - suspended
-- - running
-- - dead
-- - mormal
print(coroutine.status(co))  --> suspended
coroutine.resume(co)  --> hi
print(coroutine.status(co))  --> dead

co = coroutine.create(function ()
	  for i = 1, 10 do
		 print("co", i)
		 coroutine.yield()
	  end
end)

coroutine.resume(co)  --> co  1
print(coroutine.status(co))  --> suspended
coroutine.resume(co)
coroutine.resume(co)
coroutine.resume(co)
coroutine.resume(co)
coroutine.resume(co)
coroutine.resume(co)
coroutine.resume(co)
coroutine.resume(co)
coroutine.resume(co)
coroutine.resume(co)
coroutine.resume(co)
print(coroutine.resume(co))

co = coroutine.create(function (a, b, c)
	  print("co", a, b, c + 2)
end)
coroutine.resume(co, 1, 2, 3) --> co 1 2 5

co = coroutine.create(function (a, b)
   coroutine.yield(a+b, a-b)
end)

print(coroutine.resume(co, 20, 10))  --> true   30   10

-- yield returns any extra arguemnts passed to the corresponding resume
co = coroutine.create(function (x)
	  print("co1", x)
	  print("co2", coroutine.yield())
end)
coroutine.resume(co, "hi")  --> co1   hi
coroutine.resume(co, 4, 5)  --> co2   4    5
